package com.sunday.common.mq.rocket.brave;

import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.autoconfigure.ListenerContainerConfiguration;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;

/**
 * listener default tracing
 *
 * @author zsy
 * @see ListenerContainerConfiguration#registerContainer(String, Object, RocketMQMessageListener)
 * @see ListenerContainerConfiguration#createRocketMQListenerContainer(String, Object, RocketMQMessageListener)
 * @since 2023/8/16
 */
@RequiredArgsConstructor
public class DefaultTracingRocketMQListener implements RocketMQPushConsumerLifecycleListener {

    final RocketTracing rocketTracing;

    /**
     * 准备开始，设置消费者监听
     *
     * @param consumer
     * @see org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer#initRocketMQPushConsumer()
     */
    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {
//        consumer.getDefaultMQPushConsumerImpl()
//                .registerConsumeMessageHook(springRocketTracing.newBraveConsumeMessageHook());
//        consumer.setConsumeMessageBatchMaxSize(3);
        /**
         * Consumer Listener Brave
         */
        rocketTracing.decorateDefaultMQPushConsumer(consumer);
    }
}
